﻿using Esri.ArcGISRuntime.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WRJClient.Utils;

namespace WRJClient.Common
{
    public class RuntimeImageHelper
    {
        private Logger _logger = new Logger(typeof(RuntimeImageHelper).Name);
        private static RuntimeImageHelper _instance = null;
        private static object _lock = new object();
        public static RuntimeImageHelper Instance
        {
            get
            {
                if (_instance == null)
                {
                    lock (_lock)
                    {
                        if (_instance == null)
                        {
                            _instance = new RuntimeImageHelper();
                        }
                    }
                }
                return _instance;
            }
        }

        private Dictionary<string, RuntimeImage> _images = new Dictionary<string, RuntimeImage>();
        private RuntimeImageHelper()
        {
        }

        public RuntimeImage GetRuntimeImage(string filename)
        {
            RuntimeImage image = null;
            try
            {
                if (_images.TryGetValue(filename, out image))
                {
                    return image;
                }
                Uri uri = new Uri("Resource/Image/" + filename, UriKind.Relative);
                image = new RuntimeImage(uri);
                _images.Add(filename, image);

            }
            catch (Exception e)
            {
                _logger.Warn(e.ToString());

            }
            return image;
        }
    }
}
